/*******************************************************************************
 * Copyright (c) 2016 Avaloq Group AG and others.
 * All rights reserved. This program and the accompanying materials
 * are made available under the terms of the Eclipse Public License v1.0
 * which accompanies this distribution, and is available at
 * http://www.eclipse.org/legal/epl-v10.html
 *
 * Contributors:
 *     Avaloq Group AG - initial API and implementation
 *******************************************************************************/
package com.avaloq.tools.ddk.xtext.validation;

import org.eclipse.emf.ecore.EObject;


/**
 * The Class ValidMessage. A Valid message is a message generated by a Valid Java Validator.
 * It is either a single message (SimpleValidMessage) or a collection of messages
 * (CompoundValidMessage).
 *
 * @param <E>
 *          the element type
 */
public class ValidMessage<E extends EObject> {

  /** The message. All placeholders should be bound to values. */
  private final String message;

  /** The context. */
  private final EObject context;

  /** The offset of the diagnostic. */
  private final int offset;

  /** The length of the diagnostic. */
  private final int length;

  /** The issue data (useful to create quick fix messages. */
  private String[] data;

  /**
   * Instantiates a new valid message.
   *
   * @param message
   *          the message
   * @param context
   *          the context
   */
  public ValidMessage(final String message, final E context) {
    this.message = message;
    this.context = context;
    offset = 0;
    length = 0;
  }

  /**
   * Instantiates a new valid message.
   *
   * @param message
   *          the message
   * @param context
   *          the context
   * @param issueData
   *          the issue data
   */
  public ValidMessage(final String message, final E context, final String... issueData) {
    this.message = message;
    this.context = context;
    offset = 0;
    length = 0;
    this.data = issueData;
  }

  /**
   * Instantiates a new valid message.
   *
   * @param message
   *          the message
   * @param context
   *          the context
   * @param issueData
   *          the issue data
   */
  public ValidMessage(final String message, final E context, final int offset, final int length, final String... issueData) {
    this.message = message;
    this.context = context;
    this.offset = offset;
    this.length = length;
    this.data = issueData;
  }

  /**
   * Gets the message.
   *
   * @return the message
   */
  public String getMessage() {
    return message;
  }

  /**
   * Gets the context object.
   *
   * @return the context
   */
  public EObject getContext() {
    return context;
  }

  /**
   * Gets the offset of the diagnostic.
   *
   * @return the offset
   */
  public int getOffset() {
    return offset;
  }

  /**
   * Gets the length of the diagnostic.
   *
   * @return the length
   */
  public int getLength() {
    return length;
  }

  /**
   * Get issue data associated to the message (useful to create e.g. quick fix messages).
   *
   * @return the issueData
   */
  public String[] getData() {
    return data; // NOPMD: don't want to copy the data...
  }

}
